package com.battle.service.controller.web;

import com.battle.pojo.param.carWarCase.GetCarWarCaseListParam;
import com.battle.pojo.param.teamWarCase.*;
import com.battle.pojo.vo.teamWarCase.*;
import com.battle.service.service.in.*;
import jakarta.servlet.http.HttpServletResponse;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.domains.vo.ApiResult;
import nirvana.core.exceptions.BizException;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

import java.io.IOException;
import java.util.List;

/**
 * web/队伍战力表
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 */
@RestController
@RequestMapping("/teamWarCase/web")
public class TeamWarCaseWebController {

    private final TeamWarCaseService service;

    public TeamWarCaseWebController(TeamWarCaseService service) {
        this.service = service;
    }


    /**
     * 创建队伍战力表
     *
     * @param param
     * @return
     */
    @PostMapping("/createTeamWarCase")
    public ApiResult createTeamWarCase(@RequestBody @Valid CreateTeamWarCaseParam param) {
        service.createTeamWarCase(param);
        return ApiResult.ok();
    }


    /**
     * 修改队伍战力表
     *
     * @param param
     */
    @PutMapping("/editTeamWarCase")
    public ApiResult editTeamWarCase(@RequestBody @Valid EditTeamWarCaseParam param) {
        service.editTeamWarCase(param);
        return ApiResult.ok();
    }

    /**
     * 移除队伍战力表
     *
     * @param id
     */
    @DeleteMapping("/removeTeamWarCase")
    public ApiResult removeTeamWarCase(@RequestParam("id") Long id) {
        service.removeTeamWarCase(id);
        return ApiResult.ok();
    }

    /**
     * 获取队伍战力表详情
     *
     * @param id
     * @return
     */
    @GetMapping("/getTeamWarCase")
    public ApiResult<GetTeamWarCaseVo> getTeamWarCase(@RequestParam("id") Long id) {
        GetTeamWarCaseVo vo = service.getTeamWarCase(id);
        return ApiResult.ok(vo);
    }

    /**
     * 获取队伍战力表列表
     *
     * @param param
     * @return
     */
    @PostMapping("/getTeamWarCaseList")
    public ApiResult<PageResult<GetTeamWarCaseListVo>> getTeamWarCaseList(@RequestBody GetTeamWarCaseListParam param) {
        PageResult<GetTeamWarCaseListVo> result = service.getTeamWarCaseList(param);
        return ApiResult.ok(result);
    }


    /**
     * 导出队伍战力
     * @param response
     * @param param
     */
    @PostMapping(value = "/exportTeamWarCaseList")
    public void exportTeamWarCaseList(HttpServletResponse response, @RequestBody GetTeamWarCaseListParam param) {
        try {
            service.export(param, response);
        } catch (IOException e) {
            throw new BizException(e.getMessage());
        }
    }

}

